import request from '@/utils/request'

/**
 * 分页查询用户信息
 *
 * @param {*} query
 */
export function getUserList(query) {
  return request({
    url: '/base/auth/user/list',
    method: 'get',
    params: query
  })
}

/**
 * 创建用户
 * @param {*} baseUser
 */
export function createAuthUser(baseUser) {
  return request({
    url: '/base/auth/user/create',
    method: 'post',
    data: baseUser
  })
}

/**
 * 更新用户信息
 * @param {*} baseUser
 */
export function updateAuthUser(baseUser) {
  return request({
    url: '/base/auth/user/update',
    method: 'post',
    data: baseUser
  })
}

/**
 * 根据用户ID删除用户
 *
 * @param {*} userId
 */
export function deleteAuthUser(userId) {
  return request({
    url: '/base/auth/user/delete',
    method: 'post',
    params: { userId }
  })
}

/**
 * 解锁用户
 * @param {*} userCode
 */
export function unlockUser(userCode) {
  return request({
    url: '/base/auth/user/unlock',
    method: 'post',
    params: { userCode }
  })
}

/**
 * 用户分配角色权限
 * @param {*} userId
 * @param {*} roleIds
 */
export function updateUserRoleAuth(userId, roleIds) {
  return request({
    url: '/base/auth/user/auth',
    method: 'post',
    params: { userId },
    data: roleIds,
    headers: { 'Content-Type': 'application/json;charset-UTF-8' }
  })
}

/**
 * 获取用户角色列表
 * @param {*} userId
 */
export function getUserRoles(userId) {
  return request({
    url: '/base/auth/user/role',
    method: 'get',
    params: { userId }
  })
}

export function importAuthUser(fileobj, obj) {
  if (!fileobj || !fileobj.file) {
    return {}
  }
  const param = new FormData()
  if (obj) {
    for (const key of obj) {
      param.append(key, obj[key])
    }
  }
  param.append('file', fileobj.file)
  return request({
    method: 'post',
    url: '/base/auth/user/import',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

export function exportAuthUser(query) {
  return request({
    url: '/base/auth/user/export',
    method: 'get',
    params: query
  })
}

export function exportAuthUserTemplate() {
  return request({
    url: '/base/auth/user/exportTemplate',
    method: 'get'
  })
}
/**
 * 解锁用户
 * @param {*} userCode
 */
export function changePasswd(data) {
  return request({
    url: '/base/auth/user/passwd/change',
    method: 'post',
    data: data
  })
}
